package zong.Listener;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class MyFrame2 extends JFrame implements MouseListener {
    JButton jtb1=new JButton("点我啊");
    JButton jtb2=new JButton("再点我啊");

    public MyFrame2() {

        this.setSize(500, 500);
        this.setTitle("事件演示");
        this.setAlwaysOnTop(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(null);


        //创建按钮对象

        jtb1.setBounds(0, 10, 100, 30);
        jtb1.addMouseListener(this);


        jtb2.setBounds(100, 10, 100, 30);
        jtb2.addMouseListener(this);

        this.getContentPane().add(jtb1);//把按钮添加到界面
        this.getContentPane().add(jtb2);//把按钮添加到界面






        this.setVisible(true);
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("单击");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按下不松");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("划入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("划出");
    }
}
